import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '../store/index'
import Gonggong from '../components/gonggong.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/gonggong/home'
  },
  {
    path: '/gonggong',
    name: 'Gonggong',
    component: Gonggong,
    children: [
      {
        path: 'home',
        name: 'Home',
        component: Home,
        meta: {
          title: '后台首页',
          icon: 'el-icon-eleme'
        }

      },
      {
        path: 'shangpinguanli',
        name: 'Shangpinguanli',
        component: () => import(/* webpackChunkName: "shangpinguanli" */ '../views/shangpinguanli/index.vue'),
        meta: {
          title: '商品管理',
          icon: 'el-icon-eleme'
        }

      },
      {
        path: 'dingdanguanli',
        name: 'Dingdanguanli',
        component: () => import(/* webpackChunkName: "dingdanguanli" */ '../views/dingdanguanli/index.vue'),
        meta: {
          title: '订单管理',
          icon: 'el-icon-eleme'
        }

      },
      {
        path: 'caiwuguanli',
        name: 'Caiwuguanli',
        component: () => import(/* webpackChunkName: "caiwuguanli" */ '../views/caiwuguanli/index.vue'),
        meta: {
          title: '财务管理',
          icon: 'el-icon-eleme'
        }

      },
      {
        path: 'huiyuanzhongxin',
        name: 'Huiyuanzhongxin',
        component: () => import(/* webpackChunkName: "huiyuanzhongxin" */ '../views/huiyuanzhongxin/index.vue'),
        meta: {
          title: '会员中心',
          icon: 'el-icon-eleme'
        }

      },
      {
        path: 'caigouguanli',
        name: 'Caigouguanli',
        component: () => import(/* webpackChunkName: "caigouguanli" */ '../views/caigouguanli/index.vue'),
        meta: {
          title: '采购管理',
          icon: 'el-icon-eleme'
        }

      },

    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  store.commit("getRouters",routes)
  next()
})

export default router
